<template>
    <div class="app-container">
        <div style="text-align: center;margin-bottom: 30px">
            任务信息更新
        </div>
        <el-form :model="taskInfoForm" ref="taskInfoForm" label-width="100px">
            <el-row :gutter="10">
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="任务名称" prop="taskName">
                        <el-input type="text" v-model="taskInfoForm.taskName" placeholder="请输入任务名称" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="执行企业" prop="enterpriseId" v-if="enterPriseHidden">
                        <el-select v-model="taskInfoForm.enterpriseId"  placeholder="请选择企业" style="width: 100%" :disabled="qiye">
                            <el-option v-for="(item,index) in enterpriseList" :key="index"  :value="item.ucId" :label="item.enterpriseName"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="任务状态" prop="status">
                        <el-select style="width: 100%" v-model="taskInfoForm.status" placeholder="请选择任务状态">
                            <el-option label="已下发" :value="0"></el-option>
                            <el-option label="进行中" :value="1"></el-option>
                            <el-option label="延迟" :value="2"></el-option>
                            <el-option label="已完成" :value="3"></el-option>
                            <el-option label="已取消" :value="3"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="任务反馈" prop="feedBack">
                        <el-input v-model="taskInfoForm.feedBack" placeholder="请输入任务内容" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="开始时间" prop="startTime">
                        <el-date-picker
                                v-model="taskInfoForm.startTime"
                                type="date"
                                placeholder="选择日期"
                                style="width: 100%">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="结束时间" prop="endTime">
                        <el-date-picker
                                v-model="taskInfoForm.endTime"
                                type="date"
                                placeholder="选择日期"
                                style="width: 100%">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div slot="footer" style="text-align: center" class="dialog-footer">
            <el-button @click="caceltaskRelease">取 消</el-button>
            <el-button :loading="addLoading" type="primary" @click="updateInEnterpriseTask">修 改</el-button>
        </div>
    </div>
</template>

<script>
import {getEnterpriseTaskInfoVo,updateInEnterpriseTaskInfo} from "@/api/enterpriseTask";
import {getInEnterpriseList} from "@/api/enterprise";


export default {
    name: "UserTaskEdit",
    data() {
        return {
            taskInfoForm: {
                enterpriseIds:[]
            },
            addLoading: false,
            enterpriseList:[],
            qiye:true,


        }
    },
  computed:{
    enterPriseHidden(){
      let roleCode = this.$store.getters.roleCode;
      return roleCode=="ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"
    }
  },
    created() {
        this.getInEnterpriseList()
            let ucId = this.$route.params.ucId
            this.getEnterpriseTaskInfoVo(ucId)

    },
    methods: {
        getEnterpriseTaskInfoVo(val) {
            getEnterpriseTaskInfoVo({ucId: val}).then(res => {
                console.log(res.data)
                this.taskInfoForm = res.data
            }).catch(res => {

            })
        },
        caceltaskRelease() {
          window.history.back()
        },
        updateInEnterpriseTask() {
            this.addLoading = true
            this.$refs['taskInfoForm'].validate(valid => {
                if (valid) {
                    updateInEnterpriseTaskInfo(this.taskInfoForm).then(res => {
                        this.addLoading = false
                        this.$notify.success({
                            title: '成功',
                            message: "更新企业任务详情信息成功"
                        })
                        this.caceltaskRelease()
                    }).catch(res => {
                        this.addLoading = false
                        this.$notify.error({
                            title: '失败',
                            message: res.msg
                        })
                    })
                } else {
                    this.addLoading = false
                    console.log("表单验证不通过")
                }
            })
        },
        getInEnterpriseList(){
            getInEnterpriseList({deleted:false}).then(res=>{
                this.enterpriseList = res.data
            }).catch(error=>{

            })
        },


    }

}
</script>
